<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理平台</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
</head>
<body>
<div id="wrapper"  class="row">
			
				<h1 class="page-header col-lg-12">用户</h1>
		
			<!-- 搜索框 -->
			<div class="col-lg-12" >
				<label class="search-label">电话：</label><input type="text" id="sPhone" value="" placeholder="请输入用户手机号" class="form-control search-input width200" maxlength="21">
				<label class="search-label">姓名：</label><input type="text" id="sName" value="" placeholder="请输入用户姓名" class="form-control search-input width200" maxlength="21">
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
				<button type="button" class="btn btn-success pull-right" onclick="toAdd()"><span class="fa fa-plus"></span> 添加</button>
<%-- 				<label class="search-label">职位：</label>
				<select id="sJob" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%">
						<c:forEach items="${jobList }" var="job">
							<option value="${job.id }">${job.alias }</option>
						</c:forEach>
				</select> --%>
			</div>			
			<div class="col-lg-12 title-top">
				<div class="col-lg-12">
						<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
				</div>
				<div class="col-lg-12">
					<table id="dataTable" class="table table-striped table-hover">
						<thead>
							<tr>
								<th width="30%">真实姓名</th>
								<th width="30%">账号</th>
								<th width="15%">状态</th>
								<th width="10%">添加时间</th>
								<th width="15%">操作</th>
							</tr>
						</thead>
						<tbody id="dataList"></tbody>
					</table>
				</div>
					<div class="col-lg-12">
						<ul id="dataPagination" class="pagination-sm pull-right"></ul>
					</div>
				</div>

</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
	{{each list as item}}
	<tr id="item{{item.id}}" data-id="{{item.id}}">
		<td>{{item.trueName}}</td>
		<td>{{item.username}}</td>
		<td>{{item.enabled | flagTransform:1,'可用',0,'禁用'}}</td>
		<td>{{item.createDate }}</td>
		<td>
		{{if ${currUser.id}!=item.id}}
			<button type="button" class="btn btn-sm btn-danger btn-simple" onclick="toEditPwd('{{item.id}}')" title="修改密码"><span class="fa fa-lock fa-lg"></span></button> 
		{{/if}}
			<button type="button" class="btn btn-sm btn-primary btn-simple" onclick="toEdit('{{item.id}}')" title="编辑"><span class="fa fa-edit fa-lg"></span></button>
		{{if ${currUser.id}!=item.id}} 
			<button type="button" class="btn btn-sm btn-danger btn-simple" onclick="toDelete('{{item.id}}')" title="删除"><span class="fa fa-remove fa-lg"></span></button>
		{{/if}} 
		<button type="button" class="btn btn-sm btn-primary btn-simple" onclick="toAccredit('{{item.id}}')" title="授权"><span class="fa fa-info fa-lg"></span></button></td>
	</tr>
	{{/each}}
</script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	 var tel=$("#sPhone").val(),name=$("#sName").val();
/*      var jobs="";
		if(job!=null && job!="" && job!=undefined){
			  jobs=job.join("','");
		} 
	  */
	 var params = {
		pageSize:10,
		tel:tel,
		name:name,
// 		jobs:jobs,   
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/auth/admin/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}
function reset(){
	$("#sPhone").val("");
	$("#sName").val("");
}

$(function(){
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/auth/admin/page",{"pageSize":10},function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
});
var addDialog;
function toAdd(){
	addDialog = Kit.dialog("添加","${BASE_PATH}/auth/admin/toAdd").open();
}
var editDialog;
function toEdit(id){
	editDialog = Kit.dialog("修改","${BASE_PATH}/auth/admin/toEdit/"+id).open();
}
function onEditSuccess(id,newObject){
	$("#item"+id).replaceWith(template("list-tpl",{"list":[newObject]}));
}
var editPwdDialog;
function toEditPwd(id){
	editPwdDialog = Kit.dialog("修改密码","${BASE_PATH}/auth/admin/toEditPwd/"+id).open();
}
function toDelete(id){
	Kit.confirm("提示","您确定要删除这条数据吗？",function(){
		$.post("${BASE_PATH}/auth/admin/doDelete/"+id,function(result){
			$("#item"+id).remove();
		});
	});
}
var sRoleDialog;
function toAccredit(id){
	sRoleDialog = Kit.dialog("授权","${BASE_PATH}/auth/admin/toAccredit/"+id).open();
}
</script>
</body>
</html>